package com.hljx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljx.config.Result;
import com.hljx.dto.*;
import com.hljx.entity.SysBind;
import com.hljx.service.SysAccountingUnitService;
import com.hljx.service.SysBindService;
import com.hljx.vo.AccountingUnitDataVO;
import com.hljx.vo.HospitalDataVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 科室对照表 前端控制器
 * </p>
 *
 * @author gx
 * @since 2023-09-21
 */
@RestController
@RequestMapping("/sysBind")
@Tag(name = "科室对照")
public class SysBindController {

    @Autowired
    SysBindService service;

    @Autowired
    SysAccountingUnitService accountingUnitService;

    @Operation(summary = "查询医院数据")
    @PostMapping("/listHospitalDataByPage")
    public Result<List<HospitalDataVO>> listHospitalDataByPage(@RequestBody HospitalDataDTO hospitalDataDTO) {
        return Result.success(service.listHospitalDataByPage(hospitalDataDTO));
    }

    @Operation(summary = "查询系统数据")
    @PostMapping("/listAccountingDataByPage")
    public Result<List<AccountingUnitDataVO>> listAccountingDataByPage(@RequestBody AccountingDataPageDTO accountingDataPageDTO) {
        return Result.success(accountingUnitService.listAccountingDataByPage(accountingDataPageDTO));
    }

    @Operation(summary = "确认对照")
    @PostMapping("/updateSysBind")
    public Result<Boolean> updateSysBind(@RequestBody SysBindDTO bindDTO) {
        return Result.success(service.updateSysBind(bindDTO));
    }

    @Operation(summary = "批量对照")
    @GetMapping("/batchComparison")
    public Result<Boolean> batchComparison() {
        return Result.success(service.batchComparison());
    }

    @Operation(summary = "分页查询数据对照")
    @PostMapping("/listSysBindByPage")
    public Result<IPage<SysBind>> listSysBindByPage(@RequestBody SysBindPageDTO dto) {
        return Result.success(service.listSysBindByPage(dto));
    }

    @Operation(summary = "撤销对照数据")
    @GetMapping("/revokeSysBind")
    public Result<Boolean> revokeSysBind(@RequestParam("id") Long id) {
        return Result.success(service.revokeSysBind(id));
    }

    @Operation(summary = "导出和下载模板")
    @PostMapping("/export")
    public void export(@RequestBody ExportBindDTO dto, HttpServletResponse response) throws ClassNotFoundException {
        service.export(dto,response);
    }

    @Operation(summary = "导入")
    @PostMapping("/importExcel")
    public void importExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws ClassNotFoundException, IOException {
        service.importIw(file,response);
    }

}
